#ifndef _LOGFILE_H_
#define _LOGFILE_H_

#include "stdio.h"
#include "OSMutex.h"
#include "log_const.h"

class LogFile
{
public:
    LogFile();
    ~LogFile(){Close();};

    bool Open(char * pFilePath);
    int Write(const char *buf,int len);
    void Close();

    int GetLength(){return m_nLength;}
    bool IsOpened(){return NULL != m_pFile;}

protected:
private:
    char m_strFileName[256];
    FILE *m_pFile;
    int m_nLength;
};


class LogFileManager
{
public:
    LogFileManager();
    ~LogFileManager(){};

    bool Initialize(const char *pDir, LOG_OUT_DEV outDev);

    //int WriteLog(char *filePath, int line, char *fmt, ...);
    //int WriteLog(const char *pfunc, int line, const char *fmt, va_list va);
	virtual int WriteLog(const char *pfunc, int line, const char *fmt, va_list va);

protected:

    bool OpenNewLogFile();
    //int Write(const char *buf, int len);

    //obtain filename from filepath.
    static const char* GetFilename(char* filePath);
//private:
protected:
    bool m_bIsInitailized;
    int m_nCurrentIndex;
    char m_strLogDir[256];
    LogFile m_LogFile;
    char m_strLogBuffer[2048];
    LOG_OUT_DEV m_LogOutDev;
    OSMutex m_LogMutex;
};

// Add by caoyanming 20170815 Start
class HeartBeatLogFileManager : public LogFileManager
{
public:
	int WriteLog(const char *pfunc, int line, const char *fmt, va_list va);
};
// Add by caoyanming 20170815 End

#endif
